/*  
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License , or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; see the file COPYING.  If not, write to
      The Free Software Foundation, Inc.
      59 Temple Place, Suite 330
      Boston, MA 02111 USA

    You may contact the author by:
       e-mail:  triphop@triphop.org

*************************************************************************/

#ifndef __QX3MODEL_H
#define __QX3MODEL_H

#include <QThread>
#include <QTimer>
#include <QFile>
#include <QTextStream>
#include <QRegExp>
#include <QDir>
#include <string>
#include <linux/videodev.h>
#include <sys/mman.h>

#include "cpiaprocrwsetting.h"


typedef unsigned int uint;
/*
 * Define a model class to mediate access to the Intel Play QX3
 * microscope
 */
class Qx3Model : public QThread {

    Q_OBJECT
private:
	static Qx3Model* instance;

	// Device information
        QString dev_file;  // Path to the device
        QString cpia_file;	// Path to the proc fileentry
        int 	device;
        video_window 		vid_win;
        video_capability 	vid_caps;
        video_picture 		vid_pic;
        void *map;
        struct video_mmap v_map;
        QTimer *monitor_timer;
        bool cradlestate;
        bool buttonstate;

        void run();

        CpiaProcSetting settings;


protected:
        Qx3Model() {};
        ~Qx3Model();
        bool getLineBoolean(std::string token);

public:
        static Qx3Model* getInstance(void);

	// Light related accessors
	bool getTopLight(void);
	void setTopLight(bool);
	bool getBottomLight(void);
	void setBottomLight(bool);
	
	// image settings
	void setContrast(uint);
	uint getContrast(void);
	void setBrightness(uint);
	uint getBrightness(void);
	void setColor(uint);
	uint getColor(void);
        void setBlueGain(int);
        int getBlueGain();
        void setRedGain(int);
        int getRedGain();
        void setGreenGain(int);
        int getGreenGain();

        void setQuality(int);
        int getQuality();

	// Image setup and grabbing options
	int setupVideo(std::string devfile, std::string cpiafile);
	const char* getFrame(void);
signals:
        void buttonPressed();
        void cradleChanged(bool cradlestate);


public slots:
        void on_monitortimer_timeout();
};

#endif

